<html>
    <head>
        <meta charset="UTF-8">
        <title>查看购物车</title>
        <link href="./css/bootstrap.css" rel="stylesheet">
    </head>
    <body>
        <?php
        session_start();
        // 检查有没有登录 
        require './check.php';

        //把选中商品添加到购物车
        if (isset($_GET['pid'])) {
            $pid = $_GET['pid']; //取出参数中的商品ID
            if (array_key_exists($pid, $_SESSION['cart'])) {
                $_SESSION['cart'][$pid] ++;  //如果购物车中已经有该商品，则数量+1
            } else {
                $_SESSION['cart'][$pid] = 1; //首次购买，数量为1
            }
        }
        header("Location: index.php");
        ?>
    </body>
</html>
